package cn.z2huo.demo.spring.quartz.quartz.job;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
@DisallowConcurrentExecution
//@PersistJobDataAfterExecution
public class TestJob extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        Date fireTime = context.getFireTime();
        Date nextFireTime = context.getNextFireTime();
        Date scheduledFireTime = context.getScheduledFireTime();

        log.info("quartz test job, current time is {}, scheduled fire time is {}, current fire time is {}, next fire time is {}",
                LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"),
                DateUtil.format(scheduledFireTime, "yyyy-MM-dd HH:mm:ss"),
                DateUtil.format(fireTime, "yyyy-MM-dd HH:mm:ss"),
                DateUtil.format(nextFireTime, "yyyy-MM-dd HH:mm:ss")
        );
    }
}
